from sqlalchemy import create_engine 
from sqlalchemy import Column, Integer, String, Text 
from sqlalchemy.orm import sessionmaker 
engine = create_engine('sqlite:///saSimple.db', echo=False)
from sqlalchemy.ext.declarative import declarative_base 
Base = declarative_base()
class User(Base):
    __module__ = __name__
    __tablename__ = 'users'
    id = Column('id', Integer, primary_key=True)
    name = Column('name', Text)
    fullname = Column('fullname', Text)
    password = Column('password', Text)

    def __init__(self, name, fullname, password):
        self.name = name
        self.fullname = fullname
        self.password = password



    def __repr__(self):
        return ("User('%s', '%s', '%s', '%s')" % (self.id,
         self.name,
         self.fullname,
         self.password))



users_table = User.__table__
metadata = Base.metadata

def try_create_user(name, fullname, password):
    Session = sessionmaker(bind=engine, autoflush=True, transactional=True)
    session = Session()
    u = User(name, fullname, password)
    session.save(u)
    session.commit()



def try_list_users():
    Session = sessionmaker(bind=engine, autoflush=True, transactional=True)
    session = Session()
    users = session.query(User).all()
    for u in users:
        print u.id,
        print u



if (__name__ == '__main__'):
    print 10
    try_create_user('fred2', 'fred smith', 'secret')
    try_list_users()